import React from 'react'
import join from '@/assets/image/dataflow/node/join.svg'
import aggregate from '@/assets/image/dataflow/node/aggregate.svg'
import preprocess from '@/assets/image/dataflow/node/preprocess.svg'
import sink from '@/assets/image/dataflow/node/sink.svg'
import sql from '@/assets/image/dataflow/node/sql.svg'
import transform from '@/assets/image/dataflow/node/transform.svg'
import union from '@/assets/image/dataflow/node/union.svg'
import LeftJoin from '@/assets/image/dataflow/join/left.svg'
import RightJoin from '@/assets/image/dataflow/join/right.svg'
import FullJoin from '@/assets/image/dataflow/join/full.svg'
import InnerJoin from '@/assets/image/dataflow/join/inner.svg'

export const NodeListConfig = [
    {
        key: 'data_source',
        title: '数据读入(Data Source)',
        children: [
            {
                label: '读入',
                value: 'SqlNode',
                icon: sql
            },
            // {
            //     label: 'DAG数据读入',
            //     value: DagNode.name
            // }
        ]
    },
    {
        key: 'data_preprocess',
        title: '数据预处理(Data Preprocess)',
        children: [
            {
                label: '清洗',
                value: 'PreprocessNode',
                icon: preprocess
            },
        ]
    },
    {
        key: 'data_transform',
        title: '数据加工(Data Transform)',
        children: [
            {
                label: '聚合',
                value: 'AggregateNode',
                icon: aggregate
            },
            // {
            //     label: '转置',
            //     value: TransposeNode.name
            // },
            {
                label: '合并',
                value: 'UnionNode',
                icon: union
            },
            {
                label: '关联',
                value: 'JoinNode',
                icon: join
            }
        ]
    },
    {
        key: 'data_sink',
        title: '数据输出(Data Sink)',
        children: [
            {
                label: '写出',
                value: 'SinkNode',
                icon: sink
            },
            // {
            //     label: 'SQL数据落盘',
            //     value: PersistNode.name
            // }
        ]
    }
]

export const NodeIcons = {
    JoinNode: join,
    AggregateNode: aggregate,
    PreprocessNode: preprocess,
    SinkNode: sink,
    SqlNode: sql,
    TransposeNode: transform,
    UnionNode: union
}
export const NodeList = NodeListConfig.reduce((acc, cur) => {
    return acc.concat(cur.children)
}, [])

export const NodeMap = NodeList.reduce((acc, cur) => {
    acc[cur.value] = cur
    return acc
}, {})

export const JoinModes = [
    {
        key: 'LEFT',
        icon: LeftJoin,
        title: '左连接',
        description: '保留第一个输入所有数据',
    },
    {
        key: 'RIGHT',
        icon: RightJoin,
        title: '右连接',
        description: '保留第二个输入所有数据',
    },
    {
        key: 'INNER',
        icon: InnerJoin,
        title: '内连接',
        description: '保留两个输入共同数据',
    },
    {
        key: 'OUTER',
        icon: FullJoin,
        title: '全连接',
        description: '保留两个输入所有数据',
    },
];

export const NodeColor = (node) => {
    switch (node.type) {
        case 'UnionNode':
        case 'AggregateNode':
        case 'JoinNode':
            return '#FFA500';
        case 'PreprocessNode':
            return '#9671ff';
        case 'SqlNode':
            return '#2e74ff';
        case 'SinkNode':
            return '#45cc67';
        default:
            return '#ff0072';
    }
};